/*
 * Copyright (c) 2007 jNetX.
 * http://www.jnetx.com
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * jNetX. You shall not disclose such Confidential Information and
 * shall use it only in accordance with the terms of the license
 * agreement you entered into with jNetX.
 *
 * $Id$
 */
package com.jnetx.javax.sip.header;

import javax.sip.header.RouteHeader;
import javax.sip.address.Address;

/**
 * The Route header field is used to force routing for a request through the
 * listed set of proxies. Each host removes the first entry and then proxies
 * the Request to the host listed in that entry using it as the RequestURI.
 * <p>
 * Explicit Route assignment (if needed) for the initial dialog establishment
 * is the applications responsibility, but once established Routes are
 * maintained by the dialog layer and should not be manupulated by the
 * application. For example the SipProvider queries the dialog for Route
 * assignment and adds these to the outgoing message as needed. The
 * {@link javax.sip.address.Router} may be used by the application to determine
 * the initial Route of the message.
 *
 * @see javax.sip.header.RecordRouteHeader
 * @see javax.sip.header.HeaderAddress
 * @see javax.sip.header.Parameters
 *
 * @author <a href="mailto:dparhonin@jnetx.ru">Dmitry Parhonin</a>
 * @version $Revision$
 *
 */
public class RouteHeaderImpl extends ParametrizedHeaderBase implements RouteHeader {
    private final static RouteHeaderParser parser = new RouteHeaderParser();

    private Address address;

    public RouteHeaderImpl() {
        super(RouteHeader.NAME);
    }

    RouteHeaderImpl(byte[] data, int start, int end) {
        super(RouteHeader.NAME, data, start, end);
    }

    public Object clone() {
        final RouteHeaderImpl header = new RouteHeaderImpl();
        header.cloneBase(this);
        if (parsed) {
            header.cloneParameters(this);
            header.address = this.address;
        }
        return header;
    }

    protected HeaderParser getParser() {
        return parser;
    }

    protected String getValueAsString() {
        return address.toString();
    }

    /**
     * Sets the Address parameter of this Address.
     *
     * @param address the Address object that represents the new
     *                address of this Address.
     */
    public void setAddress(Address address) {
        parse();
        this.address = address;
        invalidateHeaderData();
    }

    /**
     * Gets the address parameter of this Address.
     *
     * @return the Address of this Address
     */
    public Address getAddress() {
        parse();
        return this.address;
    }
}
/*
 * $Log$
 */